var base = require('../../conf.js')
var Util = require('../../utils/util');
Page({
  data: {
    temp:{
      content: ''
    },
    imagePath2: "/images/icon/diamond@3x.png",
    news_img: "/images/icon/bulleted_list@3x.png",
    zan: "/images/icon/thumbs_up@3x.png",
    ranklist1: []
  },
  onLoad(){
    this.getComment()
  },
  isUpVote:function(e) {
    var commentId = e.currentTarget.dataset.id
    var self = this;
    wx.request({
      url: base.url + '/upVote',
      method: 'get',
      data: { "commentId": commentId },
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        console.log(res)
        self.getComment()
      },
    })
  },
  voteTitle: function (e) {
    this.data.temp.content = e.detail.value;
  },
  toOrder: function () {
    wx.navigateTo({
      url: "/pages/home-page/order"
    })
  },
  getComment:function(){
    var self = this;
    wx.request({
      url: base.url + '/commentInfo',
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        self.setData({
          ranklist1: res.data.data
        })
      },
    })
  },
  addComment() {
    this.Create()
  },
  Create() {
    var self = this;
    var contents = Util.json2Form(this.data.temp);
    wx.request({
      url: base.url + '/comment',
      method: 'POST',
      header: {
        'userToken': base.token_Date
      },
      data: contents,
      success: function (res) {
        console.log(contents)
        self.setData({
          temp: res.data.data
        })
        console.log(res)
        //alert("评论成功!待管理员审核后显示!")
      },
      fail: function (res) {
        console.log(2)
      }
    })
  },
})